/**
 * 药品库
 */
Lib = cc.Sprite.extend({
	libArr: [],
	openFlag:false,
	ctor:function(p){
		this._super("#lib_back.png");
		p.addChild(this,30);
		this.setTag(TAG_LIB);
		this.init();
	},
	init:function(){
		this.libArr = [];
		this.openFlag = false;
		this.setPosition(gg.width + this.width * 0.5+9,550+30);

		//天平
		var tianping = new LibButton(this, 10, TAG_LIB_TIANPING,"#tianping.png", this.callback);
		tianping.setPosition(this.width * 0.1-3, this.height * 0.5);
		//称量纸
		var chengliangzhi = new LibButton(this, 10, TAG_LIB_CHENGLIANGZHI,"#chengliangzhi.png", this.callback);
		chengliangzhi.right(tianping,5);
		//砝码盒
		var famahe = new LibButton(this, 10, TAG_LIB_FAMAHE,"#famahe.png", this.callback);
		famahe.right(chengliangzhi,5);
		//粗苯甲酸
		var ben = new LibButton(this, 10, TAG_LIB_CUBENJIASUAN,"#cubenjiasuan.png", this.callback);
		ben.right(famahe,5);
		//烧杯
		var beaker = new LibButton(this, 10, TAG_LIB_BEAKER,"#beaker.png", this.callback);
		beaker.right(ben, 5);
		//量筒
		var cyl = new LibButton(this, 10, TAG_LIB_CYLINDER,"#cylinder.png", this.callback);
		cyl.right(beaker, 5);
		//蒸馏水
		var kettle = new LibButton(this, 10, TAG_LIB_KETTLE,"#kettle.png", this.callback);
		kettle.right(cyl, 5);
		//三脚架
		var sanjiaojia = new LibButton(this, 10, TAG_LIB_SANJIAOJIA,"#sanjiaojia.png", this.callback);
		sanjiaojia.right(kettle, 5);
		//石棉网
		var shimianwang = new LibButton(this, 10, TAG_LIB_SHIMIANWANG,"#shimianwang.png", this.callback);
		shimianwang.right(sanjiaojia, 5);
		//酒精灯
		var jiujingdeng = new LibButton(this, 10, TAG_LIB_JIUJINGDENG,"#jiujingdeng1.png", this.callback);
		jiujingdeng.right(shimianwang, 5);
		//玻璃棒
		var bolibang =  new LibButton(this, 10, TAG_LIB_BOLIBANG,"#bolibang.png", this.callback);
		bolibang.right(jiujingdeng, 5);
		//活性炭
		var huoxingtan =  new LibButton(this, 10, TAG_LIB_HUOXINGTAN,"#huoxingtan.png", this.callback);
		huoxingtan.right(bolibang, 5);
		//铁架台
		var tiejiatai = new LibButton(this, 10, TAG_LIB_TIEJIATAI,"#tiejiatai.png", this.callback);
		tiejiatai.right(huoxingtan, 5);
		//热滤漏斗
		var relvloudou =  new LibButton(this, 10, TAG_LIB_RELVLOUDOU,"#relv.png", this.callback);
		relvloudou.right(tiejiatai, 5); 
		//滤纸
		var lvzhi =  new LibButton(this, 10, TAG_LIB_LVZHI,"#lvzhi1.png", this.callback);
		lvzhi.right(relvloudou, 5); 
		//抽滤装置
		var choulv = new LibButton(this, 10, TAG_LIB_CHOULV,"#air.png", this.callback);
		choulv.right(lvzhi, 5);
		//布氏漏斗
		var bushiloudou = new LibButton(this, 10, TAG_LIB_BUSHILOUDOU,"#air_funnel.png", this.callback);
		bushiloudou.right(choulv, 5);
		//表面皿
		var biaomianmin =  new LibButton(this, 10, TAG_LIB_BIAOMIANMIN,"#biaomianmin.png", this.callback);
		biaomianmin.right(bushiloudou, 5); 
		//酒精灯2
		var jiujingdeng2 = new LibButton(this, 10, TAG_LIB_JIUJINGDENG2,"#jiujingdeng1.png", this.callback);
		jiujingdeng2.right(biaomianmin, 5);
		//不锈钢勺
		var gangshao = new LibButton(this, 10, TAG_LIB_GANGSHAO,"#spoon4.png", this.callback);
		gangshao.right(jiujingdeng2, 5);
		//天平2
		var tianping2 = new LibButton(this, 10, TAG_LIB_TIANPING2,"#tianping.png", this.callback);
		tianping2.right(gangshao,5);
		//广口瓶
		var guangkouping = new LibButton(this, 10, TAG_LIB_GUANGKOUPING,"#guang.png", this.callback);
		guangkouping.right(tianping2, 5);
	},
	moveLib:function(tag,width){
		width = 75;
		var begin = false;
		for(var i in this.libArr){
			var libTag = this.libArr[i];
			if(tag == libTag){
				begin = true;
			}
			if(begin){
				var lib = this.getChildByTag(libTag);
				if(lib != null){
					lib.runAction(cc.moveBy(0.5,cc.p(-width, 0)));
				}
			}
		}
	},
	callback:function(p){
		var pos = this.getPosition(); 
		var action = gg.flow.flow.action;
		switch(p.getTag()){
			case TAG_LIB_TIANPING:
				ll.run.loadTianping(pos);
				break;
			case TAG_LIB_TIANPING2:
				ll.run.loadTianping2(pos);
				break;	
			case TAG_LIB_FAMAHE:
				ll.run.loadFamahe(pos);
				break;
			case TAG_LIB_CHENGLIANGZHI:
				ll.run.loadChengliangzhi(pos);
				break;
			case TAG_LIB_CUBENJIASUAN:
				ll.run.loadCubenjiasuan(pos);
				break;
			case TAG_LIB_SANJIAOJIA:
				ll.run.loadSanjiaojia(pos);
				break;
			case TAG_LIB_SHIMIANWANG:
				ll.run.loadShimianwang(pos);
				break;
			case TAG_LIB_BUSHILOUDOU:
				ll.run.loadBushiloudou(pos);
				break;
			case TAG_LIB_JIUJINGDENG:
				ll.run.loadJiujingdeng(pos);
				break;
			case TAG_LIB_JIUJINGDENG2:
				ll.run.loadJiujingdeng2(pos);
				break;
			case TAG_LIB_HUOCHAI:
				ll.run.loadHuochai(pos);
				break;
			case TAG_LIB_BOLIBANG:
				ll.run.showBolibang(pos);		
				break;
			case TAG_LIB_CYLINDER:
				ll.run.loadCyl(pos);
				break;
			case TAG_LIB_KETTLE:
				ll.run.loadKettle(pos);
				break;
			case TAG_LIB_HUOXINGTAN:
				ll.run.loadHuoxingtan(pos);
				break;
			case TAG_LIB_LVZHI:
				ll.run.showLvzhi(pos)
				break;
			case TAG_LIB_RELVLOUDOU:
				ll.run.loadRelvloudou(pos);
				break;
			case TAG_LIB_TIEJIATAI:
				ll.run.loadTiejiatai(pos);
				break;
			case TAG_LIB_BEAKER:
				ll.run.loadBeaker(pos);	
				break;
			case TAG_LIB_CHOULV:
				ll.run.loadChoulv(pos);
				break;
			case TAG_LIB_BIAOMIANMIN:
				ll.run.loadBiaomianmin(pos);
				break;
			case TAG_LIB_GANGSHAO:
				ll.run.loadGangshao(pos);
				break;
			case TAG_LIB_GUANGKOUPING:
				ll.run.loadGuangkouping(pos);
				break;
			default:
				break;
		}
		if(action == ACTION_NONE){
			this.moveLib(p.getTag(), p.width * p.getScale());
			p.removeFromParent(true);
		}
	},
	isOpen:function(){
		return this.openFlag; 
	},
	open:function(){
		if(this.openFlag){
			return;
		}
		this.openFlag = true;
		var move = cc.moveBy(0.4, cc.p(-this.width,0));
		var func = cc.callFunc(function(){
			var tag = gg.flow.flow.tag;
			 if(tag instanceof Array){
				 if(TAG_LIB_MIN < tag[1]){
					 // 显示箭头
					 gg.flow.location();
				 }
			 }
		}, this);
		var seq = cc.sequence(move,func);
		this.runAction(seq);
	},
	close:function(){
		if(!this.openFlag){
			return;
		}
		this.openFlag = false;
		var move = cc.moveBy(0.4, cc.p(this.width,0));
		var func = cc.callFunc(function(){
			var tag = gg.flow.flow.tag;
			if(tag instanceof Array){
				if(TAG_LIB_MIN < tag[1]){
					// 隐藏箭头
//					ll.tip.arr.out();
					ll.tip.arr.setPosition(gg.width-45,455);										
				}
			}
		}, this);
		var seq = cc.sequence(move,func);
		this.runAction(seq);
	}
});

TAG_LIB_SALT = 30001;
TAG_LIB_SPOON = 30002;
TAG_LIB_KETTLE = 30003;
//TAG_LIB_PAPER = 30004;
//TAG_LIB_ROD = 30007;
TAG_LIB_BEAKER = 30008;
//TAG_LIB_LAMP = 30009;
//TAG_LIB_SHELF = 30010;
TAG_LIB_CYLINDER = 30013;
//TAG_LIB_POT = 30014;

TAG_LIB_MIN = 10000;
TAG_LIB_TIANPING=11000;
TAG_LIB_CUBENJIASUAN=11001;
TAG_LIB_SANJIAOJIA=11002;
TAG_LIB_SHIMIANWANG=11003;
TAG_LIB_JIUJINGDENG=11004;
TAG_LIB_BOLIBANG=11005;
TAG_LIB_HUOXINGTAN=11006;
TAG_LIB_TIEJIATAI=11007;
TAG_LIB_LVZHI=11008;
TAG_LIB_RELVLOUDOU=11009;
TAG_LIB_KETTLE2=11010;
TAG_LIB_CHOULV=11011;
TAG_LIB_BUSHILOUDOU=11012;
TAG_LIB_BIAOMIANMIN=11013;
TAG_LIB_GANGSHAO=11014;
TAG_LIB_CHENGLIANGZHI=11015;
TAG_LIB_HUOCHAI=11016;
TAG_LIB_FAMAHE=11017;
TAG_LIB_TIANPING2=11018;
TAG_LIB_GUANGKOUPING=11019;
TAG_LIB_JIUJINGDENG2=11020;
libRelArr = [
             {tag:TAG_LIB_MIN, name:""},
             {tag:TAG_LIB_TIANPING, name:"托盘天平"},
             {tag:TAG_LIB_CHENGLIANGZHI, name:"称量纸"},
             {tag:TAG_LIB_FAMAHE, name:"砝码盒"},
             {tag:TAG_LIB_CUBENJIASUAN, name:"粗苯甲酸"},
             {tag:TAG_LIB_BEAKER, name:"烧杯"},
             {tag:TAG_LIB_CYLINDER, name:"量筒"},
             {tag:TAG_LIB_KETTLE, name:"蒸馏水"},
             {tag:TAG_LIB_SANJIAOJIA, name:"三脚架"},
             {tag:TAG_LIB_SHIMIANWANG, name:"石棉网"},
             {tag:TAG_LIB_JIUJINGDENG, name:"酒精灯"},
             {tag:TAG_LIB_BOLIBANG, name:"玻璃棒"},
             {tag:TAG_LIB_HUOXINGTAN, name:"活性炭"},
             {tag:TAG_LIB_TIEJIATAI, name:"铁架台"},
             {tag:TAG_LIB_RELVLOUDOU, name:"热滤漏斗"},
             {tag:TAG_LIB_LVZHI, name:"滤纸"},           
             {tag:TAG_LIB_CHOULV, name:"抽滤机"},
             {tag:TAG_LIB_BUSHILOUDOU, name:"布氏漏斗"},
             {tag:TAG_LIB_BIAOMIANMIN, name:"表面皿"},
             {tag:TAG_LIB_JIUJINGDENG2, name:"酒精灯"},
             {tag:TAG_LIB_GANGSHAO, name:"药匙"},
             {tag:TAG_LIB_TIANPING2, name:"托盘天平"},
             {tag:TAG_LIB_GUANGKOUPING, name:"广口瓶"}];




